package com.mico.jshell.command;

import org.jline.terminal.Terminal;
import org.jline.utils.InfoCmp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.shell.standard.ShellCommandGroup;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;

/**
 * @author micocube
 * projectName: springboot-example
 * packageName: com.mico.jshell.command
 * email: ldscube@gmail.com
 * createTime: 2020-01-16 16:09
 * version: 0.1
 * description:
 */
@ShellComponent
@ShellCommandGroup("system")
public class Command {
    @Autowired
    @Lazy
    private Terminal terminal;

    @ShellMethod("Clear the shell screen.")
    public void clear() {
        terminal.puts(InfoCmp.Capability.clear_screen);
    }


        @ShellMethod("System information")
        public void info() {
            System.out.println("hello, " + terminal + "!");
        }

        /**
         * 为一个命令指定多个名称
         */
        @ShellMethod(value = "Add numbers.", key = {"sum", "addition"})
        public void add(int a, int b) {
            int sum = a + b;
            System.out.println(String.format("%d + %d = %d", a, b, sum));
        }
}
